GBML manual / Instances

id

A number that uniquely identifies this instance.

Left out on purpose. GBML does not offer this, and that is a choice. There is a better way, shown below. See On the GBA below.

Syntax

id: int (read-only)

Description

Would be a number that uniquely identifies an instance, the way some event-driven engines let you store "which instance" as a plain number and look it up later.

This engine deliberately does not offer that - not because it is unbuilt, but because a ref<obj> already does the job better. Get one from instance_nearest (or instance_create), keep it in a variable or an instance field, and act on it directly - including running just that one instance's own User event with event_call's ref form. A ref<obj> carries a generation number internally, so a reference to a destroyed instance reads as gone rather than matching whatever unrelated instance later reused its slot - a protection a raw integer id could never give you.

On the GBA

Why not: a ref<T> already does this job, and it is safer. A ref knows when its instance has been destroyed and reads as gone. A plain number id would quietly match whatever new instance took over the old one’s slot. instance_nearest and friends already hand you a ref, and event_call can act on one directly.

Use instead: keep a ref<obj> to the instance instead of an id. Check it with instance_exists, or act on it directly with event_call’s ref form.

See also: instance_existsinstance_nearestevent_call